<?php

$manualList = [ 
	array( 'title' => '野马操田', 'link' => '/hldcg/search/view_u_37989.html', ), 
	array( 'title' => '野马操田(竹谱)', 'link' => '/hldcg/search/view_u_37988.html', ), 
	array( 'title' => '野马操田(百局、渊谱)', 'link' => '/hldcg/search/view_u_37987.html', ), 
	array( 'title' => '尺蚓降龙', 'link' => '/hldcg/search/view_u_37986.html', ), 
	array( 'title' => '千里独行', 'link' => '/hldcg/search/view_u_37985.html', ), 
	array( 'title' => '七星聚会', 'link' => '/hldcg/search/view_u_37984.html', )
];

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>多重任务 MultiTask</title>
<script type="text/javascript" src="../js/ajax141212.js"></script>
<script type="text/javascript" src="../js/MultiTask.js"></script>
</head>
<body>
<table align="center" width="1000" border="1" style="border:1px solid #CCC">
  <tr>
    <td>KEY</td>
    <td>棋谱</td>
    <td>链接</td>
  </tr>
<?php
		for($i=0; $i<count($manualList); $i++){
?>
  <tr>
    <td><?php echo $i?></td>
    <td><?php echo $manualList[$i]["title"]?></td>
    <td><?php echo $manualList[$i]["link"]?></td>
  </tr>
<?php
		}
?>
</table>
<br>
<div style="margin:0px auto; width:1000px;">
  <div style="height:30px; line-height:30px;text-align:center">
    <input id="button_start" type="button" value="开始"/> 
    <input id="button_pause" type="button" value="暂停"/>
    <input id="button_stop" type="button" value="停止"/>
  </div>
</div>
<script language="javascript">

var tasks = <?php echo json_encode($manualList, JSON_UNESCAPED_UNICODE)?>;

var mt = new MultiTask(tasks, 1000);

mt.onTask = function(key, task){
	console.log("开始执行任务"+key+" "+task.title+"");
	new Ajax().get({
		url : "../action/mtask_action.php"+"?key="+key+"&title="+encodeURIComponent(task.title),
		timeout : 3000,
		resultType : "json",
		onLoaded : function(result){
			console.log(result.info+"完成");
			mt.next();
		},
		onTimeout : function(){
			console.log("任务 "+key+" 超时，5秒后自动重试");
			setTimeout(function(){
				mt.retry();
			}, 5000);
		}
	});
}
	
document.getElementById("button_start").onclick = function(){
	mt.start();
}

document.getElementById("button_pause").onclick = function(){
	mt.pause();
}

document.getElementById("button_stop").onclick = function(){
	mt.stop();
}
	
mt.onEnd = function(){
	console.log("任务完成！");
};
	
</script>
</body>
</html>
